home *** CD-ROM | disk | FTP | other *** search
/ Dr. Windows 3 / dr win3.zip / dr win3 / WINPROGS / IWF12.ZIP / IWF.C < prev    next >
C/C++ Source or Header  |  1994-02-20  |  29KB  |  891 lines

  1. /*
  2. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  3. IWF.C (Image WorkFrame)
  4.  
  5. AUTHOR: Craig Muller P. Eng. 1991,1992,1993
  6.         cmuller@ccu.umanitoba.ca
  7.         Computer Vision Laboratory
  8.         Mech. Engn.,Univ. of Manitoba
  9.         Winnipeg, Manitoba. R3T 2N2
  10.  
  11. DESCRIPTION:
  12. This is the main program file for the Image WorkFrame
  13. System or IWF for short. The purpose of this software is to provide a
  14. general purpose program interface for image processing and image manipulation
  15. in a windows environment. The code can be cut an pasted to produce other
  16. programs of used as is. The program also allows the user to control the
  17. MVP-AT image capture board to perform capture and store of images.
  18.  
  19. All the code is designed in a modular fashion so that projects in image
  20. processing or conputer vision do not need to re-write all the basic code
  21. for image manipulation. Each additional software project is designed as an
  22. addition to the and has its own header file which is included here.
  23. Programmers should limit their code modifications to the program module
  24. which contains their project.
  25.  
  26. Coding conventions:
  27.  
  28.    ~~~ boxing for module title and description.
  29.    --- boxing for procedures which can be called by the user.
  30.    === boxing for exports which cannot be called by the user.
  31.  
  32. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  33. */
  34. #include <windows.h>
  35.  
  36. #pragma hdrstop
  37.  
  38. #include <stdio.h>
  39. #include <string.h>
  40. #include <io.h>
  41. #include <math.h>
  42.  
  43. #include "iwf.h"
  44. #include "module.h"
  45.  
  46. #define  PGMNAME "IWF"
  47. #define  MODULE  "IWF"
  48.  
  49. #define   VGA      640                 // VGA resolution width
  50. #define  SVGA      800                 // Super VGA resolution width
  51. #define   XGA     1024                 // XGA resolution width
  52. #define   CAD     1280                 // CAD/CAM resolution width
  53.  
  54. //========================================
  55. // Exported procedure prototypes.
  56. //========================================
  57. long far PASCAL _export WP_Main (HWND hWnd,WORD wMsg,WORD wParam,LONG lParam);
  58. BOOL FAR PASCAL _export DP_About(HWND hDlg,WORD wMsg,WORD wParam,LONG lParam);
  59. BOOL FAR PASCAL _export DP_Info(HWND hDlg,WORD wMsg,WORD wParam,LONG lParam);
  60. BOOL FAR PASCAL _export DP_Scale(HWND hDlg,WORD wMsg,WORD wParam,LONG lParam);
  61. BOOL FAR PASCAL _export DP_Transform(HWND hDlg,WORD wMsg,WORD wParam,LONG lParam);
  62. BOOL FAR PASCAL _export DP_Frame(HWND hDlg,WORD wMsg,WORD wParam,LONG lParam);
  63. BOOL FAR PASCAL _export DP_UserFile(HWND hDlg,WORD wMsg,WORD wParam,LONG lParam);
  64.  
  65.  
  66. //---------------------------------------
  67. // Private procedures.
  68. //---------------------------------------
  69. static void Load_Settings(void);
  70.  
  71. int UserDlgMessage(MSG *msg);
  72. int ToolDlgMessage(MSG *msg);
  73.  
  74. void Labeller(void);
  75. void FillColors(void);
  76. void iwf_FrameOp(int action);
  77. int Load_Item(FILE *fp,char *keyword,int *buf,int cItems);
  78.  
  79. IMAGE *MedianImage(IMAGE *image);
  80. IMAGE *SobelImage(IMAGE *image,WORD Threshold,BOOL Overlay);
  81.  
  82. //---------------------------------------
  83. // Public variables.
  84. //---------------------------------------
  85.  
  86. HANDLE    hInst;                          /* current instance handle   */
  87.  
  88. HWND  _hWndImage [MAXIMAGES];          // Window handles for images.
  89. HWND  _hWndModule[MAXMODULES];         // Window handles for modules
  90. HWND  _hWndTool  [MAXTOOLS];           // Window handles for buttons
  91. HWND  hWndMod=NULL;                    // Window handle for module.
  92. HWND  hWndSrc=NULL;                    // Window handle for source image.
  93. HWND  hWndDst=NULL;                    // Window handle for destination image.
  94.  
  95. char  _name[8][20];                    // Button names
  96. char  _cwdImage[80];                   // Image working directory
  97.  
  98. IMAGE  *_undo=NULL;                    // Undo image buffer pointer.
  99.  
  100. PALETTEENTRY peGray  [64];             // Gray scale palette for gray images
  101. PALETTEENTRY pePseudo[64];             // Pseudo color palette for alternate
  102. PALETTEENTRY peUser [128];             // User programmable section
  103. PALETTEENTRY peMain [256];             // Primary system palette
  104.  
  105. HPALETTE hPalMain;                      // Handle to the current palette.
  106.  
  107. extern WORD hist[256];
  108.  
  109. // Default user file profile
  110. char _ext[5] = ".usr";
  111. int _hsize  =   0;
  112. int _psize  =   8;
  113. int _pshift =   8;
  114. int _width  = 512;
  115. int _height = 480;
  116.  
  117. //---------------------------------------
  118. // Module prototypes.
  119. //---------------------------------------
  120. #if defined(MODULE0)
  121. int MODULE0(HWND hWnd);
  122. #endif
  123. #if defined(MODULE1)
  124. int MODULE1(HWND hWnd);
  125. #endif
  126. #if defined(MODULE2)
  127. int MODULE2(HWND hWnd);
  128. #endif
  129. #if defined(MODULE3)
  130. int MODULE3(HWND hWnd);
  131. #endif
  132. #if defined(MODULE4)
  133. int MODULE4(HWND hWnd);
  134. #endif
  135. #if defined(MODULE5)
  136. int MODULE5(HWND hWnd);
  137. #endif
  138. #if defined(MODULE6)
  139. int MODULE6(HWND hWnd);
  140. #endif
  141. #if defined(MODULE7)
  142. int MODULE7(HWND hWnd);
  143. #endif
  144.  
  145. //--------------------------------------
  146. // External dialog windows.
  147. //--------------------------------------
  148. #if defined (DIALOG0)
  149. extern HWND DIALOG0;
  150. #endif
  151. #if defined (DIALOG1)
  152. extern HWND DIALOG1;
  153. #endif
  154. #if defined (DIALOG2)
  155. extern HWND DIALOG2;
  156. #endif
  157. #if defined (DIALOG3)
  158. extern HWND DIALOG3;
  159. #endif
  160. #if defined (DIALOG4)
  161. extern HWND DIALOG4;
  162. #endif
  163. #if defined (DIALOG5)
  164. extern HWND DIALOG5;
  165. #endif
  166. #if defined (DIALOG6)
  167. extern HWND DIALOG6;
  168. #endif
  169. #if defined (DIALOG7)
  170. extern HWND DIALOG7;
  171. #endif
  172.  
  173.  
  174.  
  175.  
  176.  
  177. /*
  178. ==========================================================================
  179. int PASCAL WinMain(HANDLE hInstance,HANDLE hPrevInstance,
  180.                    LPSTR  lpCmdLine,int    nCmdShow)
  181.  
  182. Description:
  183.  
  184. WINDOWS ENTRY POINT CODE.
  185.  
  186. Windows initial entry point for the program. This is the startup code for
  187. the program. It initializes the top level window, sets up code sharing
  188. (if another instance of the program is running), and begins a message loop.
  189. This code should not be modified by module programmers.
  190.  
  191. If this function must abort before entering the msg loop, it returns the
  192. conventional value NULL.
  193. ==========================================================================
  194. */
  195. int PASCAL WinMain(HANDLE hInstance,        /* current instance       */
  196.                          HANDLE hPrevInstance,    /* previous instance      */
  197.                          LPSTR  lpCmdLine,        /* cmd line               */
  198.                          int    nCmdShow)         /* show type (open/icon)  */
  199.    {
  200.    int  x0,y0,w,h,cx,cy;
  201.    MSG  msg;
  202.    HWND hWnd;                              
  203.    WNDCLASS wc;
  204.  
  205.    hInst = hInstance;                            // Save the instance handle.
  206.    if (!hPrevInstance)                           // Other instances running?
  207.       {
  208.       wc.lpszClassName = MODULE"Main";           // Name for CreateWindow.
  209.       wc.style         = CS_DBLCLKS;             // Qualifying double clicks 
  210.       wc.lpfnWndProc   = (WNDPROC)WP_Main;       // Func to get msgs
  211.       wc.cbClsExtra    = 0;                      // No per-class extra data. 
  212.       wc.cbWndExtra    = 0;                      // No per-window extra data 
  213.       wc.hInstance     = hInstance;              // App that owns the class  
  214.       wc.hIcon         = LoadIcon(hInst,MODULE); // Loads icon 
  215.       wc.hCursor       = LoadCursor(NULL,IDC_ARROW);
  216.       wc.hbrBackground = COLOR_APPWORKSPACE+1;
  217.       wc.lpszMenuName  = MODULE;                 // Name of menu resource
  218.  
  219.       if (!RegisterClass(&wc))                   // Initialize new window class.
  220.          {
  221.          char sz[80];
  222.  
  223.          sprintf("Unable to register <%s> class",(char *)wc.lpszClassName);
  224.          MessageBeep(MB_ICONEXCLAMATION);
  225.          MessageBox(NULL,sz,"Error",MB_OK | MB_ICONEXCLAMATION);
  226.          return (FALSE);                         // Exits if unable.
  227.          }
  228.       }
  229.  
  230.    /*
  231.    Perform initializations that apply to a specific instance, those that 
  232.    cannot be shared by multiple instances. Save the instance handle in
  233.    static variable, which will be used in many subsequence calls from
  234.    this application to Windows.
  235.  
  236.    WRIPS is currently compatible with 3 display resolutions:
  237.  
  238.    1. 640x480  VGA